package com.sxpi.order.controller;

import cn.hutool.core.bean.BeanUtil;
import com.sxpi.common.result.R;
import com.sxpi.order.dto.OrderDto;
import com.sxpi.order.pojo.Order;
import com.sxpi.order.service.IOrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: 董伟豪
 * @Date: 2022/10/25 20:09
 */
@RestController
@Slf4j
public class OrderController{

    @Autowired
    private IOrderService orderService;

    /**
     * 下单方法
     * @param orderDto
     * @return
     */
    @PostMapping("/order/create")
    public R saveOrder(@RequestBody OrderDto orderDto){
        Order order = orderService.saveOrder(orderDto);
        // return R.ok().put("order",order);
        return R.ok(BeanUtil.beanToMap(order));
    }

    /**
     * 根据订单编号查询订单信息
     * @param orderNo
     * @return
     */
    @PostMapping("/order/info/{orderNo}")
    public R getOrderInfoByOrderNo(@PathVariable("orderNo") String orderNo) {
        Order order = orderService.getOrderInfoByOrderNO(orderNo);
        return R.ok().put("flag", order != null);
    }
}
